jest.setTimeout(30000)
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')

describe('actionSheet', () => {
  let page;
  if (isAndroid) {
    it('android not support', () => {
      expect(1).toBe(1)
    })
    return
  }

  it('actionSheet can show in onLaunch', async () => {
    page = await program.currentPage()
    expect(page.path).toBe('pages/index/index')
    await page.waitFor('view')

    const image = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(image).toSaveImageSnapshot();
  });
  it('check dialogPages', async () => {
    const lifeCycle = await page.callMethod('getLifeCycleNum')
    expect(lifeCycle).toBe(1)
  });
  it('click mask should close actionSheet', async () => {
    await program.tap({
      x: 300,
      y: 300
    })
    await page.waitFor(1000)

    const image = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(image).toSaveImageSnapshot();
  });
  it('showActionSheet with custom style', async () => {
    await page.callMethod('showActionSheet')
    await page.waitFor(1000)
    const image = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(image).toSaveImageSnapshot();
  })
  it('showActionSheet with long content & should hide pre actionSheet', async () => {
    await page.callMethod('showActionSheetLongContent')
    await page.waitFor(1000)
    const image = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(image).toSaveImageSnapshot();
  })
  it('hideActionSheet', async () => {
    await page.callMethod('hideActionSheet')
    await page.waitFor(1000)
    const image = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(image).toSaveImageSnapshot();
  })
  it('close page should close actionSheet', async () => {
    page = await program.navigateTo('/pages/about/about');
    await page.callMethod('showActionSheet')

    await page.waitFor(1000)
    const imageWithActionSheet1 = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(imageWithActionSheet1).toSaveImageSnapshot();

    page = await program.navigateBack()
    await page.waitFor(1000)
    const imageAfterBack = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(imageAfterBack).toSaveImageSnapshot();

    page = await program.navigateTo('/pages/about/about');
    await page.callMethod('showActionSheet')

    await page.waitFor(1000)
    const imageWithActionSheet2 = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(imageWithActionSheet2).toSaveImageSnapshot();

    page = await program.reLaunch('/pages/index/index')
    await page.waitFor(1000)
    const imageAfterReLaunch = await program.screenshot({
      deviceShot: true,
      area: {
        x: 0,
        y: 200,
      }
    });
    expect(imageAfterReLaunch).toSaveImageSnapshot();
  })
});